#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
using namespace std;
bool isPalidrom(int n)
{
	int s = 0, k = n;
	while (k != 0)
	{
		s *= 10;
		s += k % 10;
		k /= 10;
	}
	if (s == n)
		return 1;
	return false;
}

bool isPrime(int n)
{
	for (int i = 3; i < sqrt(i); i = i + 2)
	{
		if (n % i == 0)
			return false;
	}
	return true;
}
int main()
{
	int a = 0, b = 0;
	cin >> a >> b;
	if (a % 2 == 0)
		a++;
	if (b > 10000000)
		b = 10000000;
	for (int i = a; i <= b; i=i+2)
	{
		if (isPalidrom(i) && isPrime(i))
		{
			cout << i << endl;
		}
	}
	return 0;
}